<template>
  <div class="home">
    <div class="content">
      <!-- 头部区域 -->
      <div class="header">
        <div class="title">
          Cyan外卖
        </div>
        <div class="location">
          <van-icon name="location-o" size="20" />
          <span>Cyan</span>
          <van-icon name="arrow" />
        </div>
      </div>
      <div class="main">
        <div class="main-bg">
          <!-- 内容区搜索区 -->
          <div class="search">
            <input type="text">
            <div class="search-text">搜索</div>
          </div>
          <div class="sort">
            <div class="big-sort">
              <div v-for="(item, index) in big_sort" :key="index">
                <svg class="icon" aria-hidden="true">
                  <use :xlink:href="`#${item.icon}`"></use>
                </svg>
                {{ item.name }}
              </div>
            </div>
            <div class="small-sort">
              <div v-for="(item, index) in small_sort" :key="index">
                <svg class="icon" aria-hidden="true">
                  <use :xlink:href="`#${item.icon}`"></use>
                </svg>
                {{ item.name }}
              </div>
            </div>
          </div>
          <van-tabs v-model:active="active" class="vantab" color="#ff4c00">
            <van-tab v-for="(item, index) in content_nav_list" :title="item.tab" :key=index>
              <nav-List :navList="item.data" />
            </van-tab>
          </van-tabs>
        </div>
      </div>


    </div>
    <Footer />
  </div>

</template>

<script setup lang="js">
import { onMounted, reactive, ref, toRefs } from "vue";
import Footer from "../../components/Footer.vue"
import navList from "./components/navList.vue";
// import axios from "axios";
import { getApiHomeData } from "@/api/api";

const active = ref(0)
const data = reactive({
  big_sort: [],
  small_sort: [],
  content_nav_list: []
})
const getHomeData = () => {
  getApiHomeData().then((res) => {
    // console.log(res);
    data.big_sort = res.big_sort
    data.small_sort = res.small_sort
    data.content_nav_list = res.content_nav_list
  })
  // 这是使用axios方法渲染数据
  // axios.get("/home/getHomeData").then((res) => {
  //   // console.log(res);
  //   const { code, homeData } = res.data
  //   if (code === 200) {


  //   }
  // })
}
onMounted(() => {
  getHomeData()
})
// 解构所有需要的数据
const { big_sort, small_sort, content_nav_list } = toRefs(data)
</script>

<style scoped lang="less">
.home {
  display: flex;
  flex-flow: column;
  height: 100%;
  font-size: 10px;

  .content {
    flex: 1;
    overflow-y: auto;

    .header {
      background-image: linear-gradient(#ffc400, #fff);
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 15px 15px 30px 15px;

      .title {
        font-size: 20px;
        font-weight: 600;
      }

      .location {
        span {
          margin: 0 5px;
          font-size: 14px;
        }
      }
    }

    .main {
      margin-top: -30px;

      .main-bg {
        background-image: linear-gradient(#fff, #f5f5f5);
        padding: 10px 20px 0px 20px;
        border-radius: 30px 30px 0px 0px;

        .search {
          position: relative;

          input {
            width: 100%;
            border: 1px solid #ffc400;
            border-radius: 20px;
            height: 30px;
          }

          .search-text {
            position: absolute;
            right: -6px;
            top: 1px;
            background-color: #ffc400;
            border-radius: 15px;
            width: 50px;
            height: 30px;
            font-size: 14px;
            text-align: center;
            line-height: 30px;
          }
        }

        .sort {
          padding: 20px 0;

          .big-sort {
            display: flex;

            div {
              flex: 1;
              display: flex;
              justify-content: center;
              flex-flow: column;
              align-items: center;

              .icon {
                width: 40px;
                height: 40px;
                margin-bottom: 5px;
              }
            }
          }

          .small-sort {
            display: flex;
            flex-wrap: wrap;
            margin-top: 10px;

            div {
              display: flex;
              justify-content: center;
              flex-flow: column;
              align-items: center;
              width: 20%;
              padding-top: 20px;

              .icon {
                width: 40px;
                height: 40px;
                margin-bottom: 5px;
              }
            }
          }
        }

        .vantab {
          padding: 0 20px 10px 0;
        }
      }
    }
  }
}
</style>